using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_PayOnLine : Admin, IRequiresSessionState
{
	private Pagination _pageHand = null;
	private string wherestr = "";
	private string linkhead = "";
	private IDbDataParameter[] param;
	private ArrayList al = new ArrayList();
	protected TextBox TxtPayNum;
	protected TextBox TxtUserName;
	protected Button Button1;
	protected GridView GridView1;
	protected Literal PagePanel;
	protected ObjectDataSource ObjectDataSource1;
	public virtual Pagination pageHand
	{
		get
		{
			Pagination pageHand;
			if (this._pageHand == null)
			{
				this._pageHand = new Pagination();
				this._pageHand.SQL_CloseTablePre = false;
				this._pageHand.SQL_Fields = "*,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName";
				this._pageHand.P_Object = "记录";
				pageHand = this._pageHand;
			}
			else
			{
				pageHand = this._pageHand;
			}
			return pageHand;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (Fetch.Get("action") == "repair")
		{
			this.Repay();
		}
		else
		{
			if (!base.IsPostBack)
			{
				this.BindList();
			}
		}
	}
	protected void BindList()
	{
		this.Questing();
		int num = Fetch.GetID("page");
		if (num == 0)
		{
			num = 1;
		}
		int pageSize = this.GridView1.PageSize;
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		if (this.param != null)
		{
			this.GridView1.DataSource = this.pageHand.GetDataTable("HL_PayOnline", num, pageSize, "OnlinePayID", this.wherestr, "", this.conn, this.param);
		}
		else
		{
			this.GridView1.DataSource = this.pageHand.GetDataTable("HL_PayOnline", num, pageSize, "OnlinePayID", this.wherestr, "", this.conn, null);
		}
		this.GridView1.DataBind();
		this.PagePanel.Text = this.pageHand.ShowPagePanel();
	}
	protected void OnSelect(object sender, EventArgs e)
	{
		this.BindList();
	}
	protected void Questing()
	{
		string text = Fetch.Get("PayNum");
		if (text != string.Empty)
		{
			this.TxtPayNum.Text = text;
		}
		else
		{
			text = this.TxtPayNum.Text;
		}
		if (text != string.Empty)
		{
			this.wherestr += "and PayNum=@PayNum ";
			this.al.Add(this.conn.CreateParameter("@PayNum", DbType.String, text));
			this.linkhead = this.linkhead + "&PayNum=" + base.Server.UrlDecode(text);
		}
		string text2 = Fetch.Get("un");
		if (text2 != string.Empty)
		{
			this.TxtUserName.Text = text2;
		}
		else
		{
			text2 = this.TxtUserName.Text;
		}
		if (text2 != string.Empty)
		{
			this.wherestr += "and UserName like '%'+@UserName+'%' ";
			this.al.Add(this.conn.CreateParameter("@UserName", DbType.String, text2));
			this.linkhead = this.linkhead + "&un=" + base.Server.UrlDecode(text2);
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "where");
		}
	}
	protected void Repay()
	{
		int iD = Fetch.GetID("ID");
		if (iD > 0)
		{
			PayOnline payOnline = new PayOnline(this.conn);
			DataTable byID = payOnline.GetByID(iD);
			if (byID.Rows.Count > 0)
			{
				string text = byID.Rows[0]["eBankName"].ToString();
				int num = Convert.ToInt32(byID.Rows[0]["PayStatus"]);
				if (num == 0)
				{
					int num2 = Convert.ToInt32(byID.Rows[0]["UserID"]);
					decimal d = Text.ToDecimal(this.conn.GetScalar("Select Balance From HL_User Where UserID=" + num2, new IDbDataParameter[0]));
					decimal num3 = Convert.ToDecimal(byID.Rows[0]["PayMoney"]);
					this.conn.BeginTransaction();
					try
					{
						this.conn.ExecuteTransaction("Update HL_PayOnline Set PayStatus=1 Where OnlinePayID=" + iD);
						this.conn.ExecuteTransaction(string.Concat(new object[]
						{
							"Update HL_User Set Balance=",
							d + num3,
							" Where UserID=",
							num2
						}));
						this.conn.ExecuteTransaction(string.Concat(new object[]
						{
							"Insert Into HL_AccountDetails(UserID,cMoney,cType,uBalance,CreateTime,Remark) values(",
							num2,
							",",
							num3,
							",1,",
							d + num3,
							",'",
							DateTime.Now,
							"','",
							text,
							"在线充值(手动修复)')"
						}));
					}
					catch
					{
						this.conn.Rollback();
						this.WriteErrMsg("", Language.Get("Common/Fail", "0"), "");
					}
					this.conn.Commit();
					this.WriteSuccessMsg("", Language.GetAdminMsg("Voucher/RepairSuccess"), "Admin_PayOnLine.aspx");
				}
				else
				{
					this.WriteSuccessMsg("", Language.GetAdminMsg("Voucher/NoRepair"), "");
				}
			}
		}
	}
}
